import { http } from "@/utils/http";

import {
  type userInfoType,
  type regionResType,
  type userRangeRegionsDataType
} from "@/api/types";
import { useUserStoreHook } from "@/store/modules/user";
import { whReqBaseUrl as VITE_REQUEST_BASE_SAAS_API } from "@/api/common";

/** 登录 */
export const getLogin = (data?: object) => {
  // console.log("getLogin data:", data);
  return http.postForm<{ accessToken: string }>(
    `${VITE_REQUEST_BASE_SAAS_API}/users/login`,
    { ...data }
  );
};

/**
 * 获取用户详情
 */

export const getUserInfo = () => {
  return http.request<userInfoType>(
    "get",
    `${VITE_REQUEST_BASE_SAAS_API}/users/currentUserInfo`
  );
};

/**
 * 获取公共的省市区列表
 * @returns
 */
export function getCommonRegions() {
  return http.request<regionResType>(
    "get",
    `${VITE_REQUEST_BASE_SAAS_API}/cfg/regions`
  );
}

// 查询用户查看范围内省市区
export function getUserRegions(userId: string) {
  return http.request<userRangeRegionsDataType>(
    "get",
    `${VITE_REQUEST_BASE_SAAS_API}/cfg/userRangeRegions`,
    { params: { userId } }
  );
}
